#include <string>
#include <Windows.h>

namespace superunzip::utils
{
    bool endsWith(const std::string &str, const std::string &suffix)
    {
        if (suffix.size() > str.size())
            return false;
        return str.rfind(suffix) == str.size() - suffix.size();
    }

    std::string gbk_to_utf8(const char *gbk_str)
    {
        // GBK → Wide Char (UTF-16)
        int wlen = MultiByteToWideChar(CP_ACP, 0, gbk_str, -1, nullptr, 0);
        wchar_t *wstr = new wchar_t[wlen];
        MultiByteToWideChar(CP_ACP, 0, gbk_str, -1, wstr, wlen);

        // Wide Char → UTF-8
        int ulen = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr);
        char *utf8_str = new char[ulen];
        WideCharToMultiByte(CP_UTF8, 0, wstr, -1, utf8_str, ulen, nullptr, nullptr);

        std::string result(utf8_str);
        delete[] wstr;
        delete[] utf8_str;
        return result;
    }

}